//
//  BCViewControEx.swift
//  DianXia
//
//  Created by you&me on 2017/12/19.
//  Copyright © 2017年 you&me. All rights reserved.
//

import Foundation

extension UIViewController {
    var ex_robotState:AnyObserver<RobotState>{
        return Binder(self) { bcVC, state in
            if state.isOpen == false {
                let  vc = UIStoryboard.viewController(from: .Home, viewControllerClass: OpenFailVC.self)
                self.present(vc, animated: false, completion: nil)
            }else {
                if state.iderfier == "finishRepairSuccess" || state.iderfier == "finishSupportSuccess" || state.iderfier == "activeSuccess"{
                    //正确完成补货、维护,激活设备 并且设备取得完整响应
                    for i in 0..<UserActivingTasks.share.tasks.count {
                        let bcTask = UserActivingTasks.share.tasks[i]
                        if bcTask.code == state.code {
                         UserActivingTasks.share.tasks.remove(at: i)
                        }
                    }
                    let vc = UIStoryboard.initialViewControllerFromStoryboard(.Home) as! UIViewController
                    UIApplication.shared.keyWindow?.rootViewController = vc
                }
            }
        }.asObserver()
    }
}
